// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   NetDsign.java

package com.vandagroup.security;

import com.vandagroup.common.bean.BaseBean;
import com.vandagroup.common.bo.UserContext;
import java.sql.SQLException;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

// Referenced classes of package com.vandagroup.security:
//            SignPO, SignFormBean, SignBO

public class NetDsign
{

    public static final String CARequired = "CARequired";
    public static final String SIGNATURE = "signature";
    public static HashMap configInfo = null;
    SignFormBean signBean;
    HttpServletRequest request;
    UserContext user;

    public static HashMap getConfigInfo(String funcID)
        throws Exception
    {
        if(configInfo == null)
        {
            configInfo = new HashMap();
            SignPO po = new SignPO();
            BaseBean beans[] = po.query("select funcID,engTag,chsTag from signConfig");
            HashMap hm = null;
            for(int i = 0; i < beans.length; i++)
            {
                hm = (HashMap)configInfo.get(beans[i].get("funcID"));
                if(hm == null)
                {
                    hm = new HashMap();
                    configInfo.put(beans[i].get("funcID"), hm);
                }
                hm.put(beans[i].get("engTag"), beans[i].get("chsTag"));
            }

        }
        return (HashMap)configInfo.get(funcID);
    }

    public void bengin()
        throws Exception
    {
        if(!isNeed())
            return;
        if(attachedVerify() != 0)
        {
            throw new Exception("服务器验签失败");
        } else
        {
            saveSignature();
            return;
        }
    }

    public void end()
        throws Exception
    {
        if(!isNeed())
        {
            return;
        } else
        {
            updateStat("1");
            return;
        }
    }

    public void endExp()
        throws Exception
    {
        if(!isNeed())
        {
            return;
        } else
        {
            updateStat("2");
            return;
        }
    }

    public NetDsign(HttpServletRequest request, UserContext user)
    {
        this.request = null;
        this.user = null;
        this.request = request;
        this.user = user;
    }

    public String getCustIP()
    {
        return request.getRemoteAddr();
    }

    public int attachedVerify()
    {
        return 0;
    }

    public void saveSignature()
        throws Exception
    {
        if(!"0".equals(request.getSession().getAttribute("CARequired")))
            return;
        signBean = new SignFormBean();
        SignBO signBo = new SignBO();
        signBean.setSignText(request.getParameter("signature"));
        try
        {
            signBo.add(signBean);
        }
        catch(SQLException e)
        {
            throw new Exception("保存出错");
        }
    }

    public void updateStat(String v)
        throws SQLException
    {
        if(!isNeed())
            return;
        SignBO signBo = new SignBO();
        if(signBean != null)
            signBo.update(signBean.getId(), v);
    }

    public boolean isNeed()
    {
        return request.getParameter("signature") != null;
    }

    public String formatDN(String DN)
    {
        if(DN == null)
            return null;
        String DNs[] = DN.split(",");
        String DNf = "";
        for(int i = 0; i < DNs.length; i++)
        {
            DNf = DNf + DNs[i];
            if(i < DNs.length - 1)
                DNf = DNf + ", ";
        }

        return DNf;
    }

}
